﻿/***************************************************************************
 创建者: 华磊
 开始时间: 2019.9.20
 copyright: (C) 华友高科
 ***************************************************************************/
#include "mapeditwindow.h"
#include "global.h"
#include "scene.h"
#include <QFileIconProvider>
#include "./dockview.h"
#include "./dockmaptree.h"
#include "./dockproperty.h"
#include "./dockblock.h"
#include "./dockgroup.h"
#include "mapfileparse.h"
#include <QMessageBox>
#include "../CommunicateDelegate/communicatenormaldelegate.h"
#include "../CommunicateDelegate/globaldata.h"
#include "mapstationeditview.h"
#include "patheditview.h"
#include "mapmergeview.h"

extern double g_mapRatio;
extern double g_itemDisplayRatio;

MapEditWindow::MapEditWindow(CommunicateNormalDelegate *communicateNormalIn, GlobalData *globalDataIn,
                             OneMap *_oneMap, QWidget *parent) : QMainWindow(parent),
    oneMap(_oneMap)
{
    communicateNormal=communicateNormalIn;
    globalData=globalDataIn;
    mapfileParser=new MapFileParse;
    choosedSpirit=NULL;
    lastoneMap=new OneMap();
    setWindowTitle("调度客户端－地图编辑");
    createActions();
    createStatusBar();

    mapStationEditView=new MapStationEditView(_oneMap,this);
    mapStationEditView->hide();

    pathEditView=new PathEditView(_oneMap,this);
    pathEditView->hide();

    mapMergeView=new MapMergeView(_oneMap,this);
    mapMergeView->hide();

    init();
}

MapEditWindow::~MapEditWindow()
{
    delete oneMap;
}

void MapEditWindow::init()
{

    connect(&msgCenter,SIGNAL(sig_connection_connected()),this,SLOT(onServerConnect()));
    connect(&msgCenter,SIGNAL(sig_connection_disconnected()),this,SLOT(onServerDisconnect()));
    connect(&msgCenter,SIGNAL(sig_connection_conntectting()),this,SLOT(onServerConnectting()));

    connect(&msgCenter,SIGNAL(sendRequestFail()),this,SLOT(onSendFail()));
    connect(&msgCenter,SIGNAL(waitResponseTimeOut()),this,SLOT(onWaitResponseTimeOut()));
    connect(&msgCenter,SIGNAL(tip(QString)),this,SLOT(onTip(QString)));
    connect(&msgCenter,SIGNAL(err(int,QString)),this,SLOT(onErr(int,QString)));
    connect(&msgCenter,SIGNAL(sendNewRequest()),this,SLOT(onNewRequest()));

    connect(&msgCenter,SIGNAL(mapSetSuccess()),this,SLOT(onNewRequest()));
    connect(&msgCenter,SIGNAL(mapGetSuccess()),this,SLOT(onNewRequest()));

    //对树 的操作( 只有两个操作 添加楼层、选择不同的节点)
    connect(dockMapTree,SIGNAL(sig_addFloor(MapFloor*)),dockView,SLOT(slot_addFloor(MapFloor*)));
    connect(dockMapTree,SIGNAL(sig_chooseSpirit(MapSpirit*)),dockProperty,SLOT(slot_showSpirit(MapSpirit*)));
    connect(dockMapTree,SIGNAL(setchooseSpirit_signal(MapSpirit*)),this,SLOT(slot_chooseSpirit(MapSpirit*)));
    connect(dockMapTree,SIGNAL(sig_chooseSpirit(MapSpirit*)),this,SLOT(slot_chooseSpirit(MapSpirit*)));
    connect(dockMapTree,SIGNAL(sig_chooseSpirit(MapSpirit*)),dockView,SLOT(slot_selectChanged(MapSpirit *)));

    connect(dockView,SIGNAL(sig_currentMousePos(QPointF)),this,SLOT(slot_currentMousePos(QPointF)));
    connect(dockView,SIGNAL(sig_cancelTool()),this,SLOT(slot_cancelTool()));
    connect(this,SIGNAL(sig_setTool(int)),dockView,SIGNAL(sig_setTool(int)));

    connect(dockView,SIGNAL(sig_add_remove_spirit()),dockMapTree,SLOT(refresh()));
    connect(dockView,SIGNAL(sig_add_remove_spirit()),dockProperty,SLOT(slot_shownull()));
    connect(dockView,SIGNAL(sig_chooseChanged(MapSpirit*)),dockMapTree,SLOT(slot_chooseChanged(MapSpirit*)));
    connect(dockView,SIGNAL(sig_chooseChanged(MapSpirit*)),dockProperty,SLOT(slot_showSpirit(MapSpirit*)));
    connect(dockView,SIGNAL(sig_propertyChanged(MapSpirit*)),dockProperty,SLOT(slot_propertyChanged(MapSpirit*)));

    //属性窗口 修改 到 地图窗口的信号
    connect(dockProperty,SIGNAL(sig_propertyChanged(MapSpirit *)),dockView,SIGNAL(sig_propertyChangedFromProperty(MapSpirit*)));
    connect(dockProperty,SIGNAL(sig_propertyChanged(MapSpirit *)),dockMapTree,SLOT(refresh()));

    connect(this,SIGNAL(sig_propertyChanged(MapSpirit *)),dockProperty,SLOT(slot_propertyChanged(MapSpirit*)));
    connect(this,SIGNAL(sig_propertyChanged(MapSpirit *)),dockView,SIGNAL(sig_propertyChangedFromProperty(MapSpirit*)));

    connect(blockView,SIGNAL(sig_chooseSpirit(MapSpirit*)),dockProperty,SLOT(slot_showSpirit(MapSpirit *)));
    connect(groupView,SIGNAL(sig_chooseSpirit(MapSpirit*)),dockProperty,SLOT(slot_showSpirit(MapSpirit *)));

    connect(blockView,SIGNAL(sig_chooseSpirit(MapSpirit*)),dockView,SLOT(slot_selectChanged(MapSpirit *)));
    connect(groupView,SIGNAL(sig_chooseSpirit(MapSpirit*)),dockView,SLOT(slot_selectChanged(MapSpirit *)));

    connect(this,SIGNAL(sig_setSelectHand()),dockView,SIGNAL(sig_selectHand()));
    connect(this,SIGNAL(sig_setSelectSelect()),dockView,SIGNAL(sig_selectSelect()));
    connect(this,SIGNAL(sig_addBkg(int)),dockView,SLOT(slot_addBkg(int)));
    //connect(this,SIGNAL(sig_addBkg(MapBackground*)),dockMapTree,SLOT(refresh()));
    connect(this,SIGNAL(sig_displayAll()),dockView,SIGNAL(sig_displayAll()));
    connect(this,SIGNAL(sig_repaint()),dockView,SIGNAL(sig_repaint()));

    //id 坐标　path 修改
    connect(pathEditView,SIGNAL(updateMapShow_signal()),this,SLOT(updateMapShow_slot()));
    connect(mapStationEditView,SIGNAL(updateMapShow_signal()),this,SLOT(updateMapShow_slot()));
    connect(mapMergeView,SIGNAL(updateMapShow_signal()),this,SLOT(updateMapShow_slot()));

    connect(mapStationEditView,SIGNAL(sig_propertyChanged(MapSpirit *)),dockView,SIGNAL(sig_propertyChangedFromProperty(MapSpirit*)));
    connect(mapStationEditView,SIGNAL(sig_propertyChanged(MapSpirit *)),dockMapTree,SLOT(refresh()));
    connect(mapStationEditView,SIGNAL(sig_propertyChanged(MapSpirit *)),dockProperty,SLOT(slot_propertyChanged(MapSpirit*)));

    QMetaObject::connectSlotsByName(this);
}

void MapEditWindow::loginControllerSucess_slot()
{
       on_toolLoad_triggered(true);
}

//void MapEditWindow::controllerLogin_slot(QVector<int> controllerIpAddress, QVector<int> hmiIpAddress, QString port, QString passwardString, int selectedAccount)
//{
//    on_toolLoad_triggered(true);
//}

void MapEditWindow::updateMapShow_slot()
{
    dockMapTree->refresh();
    dockView->initialScene();
    emit sig_displayAll();
}

void MapEditWindow::slot_chooseSpirit(MapSpirit *spiritIn)
{
    choosedSpirit=spiritIn;
}

void MapEditWindow::onServerConnect()
{
    statusbar_info(QStringLiteral("已连接"));
}

void MapEditWindow::onServerDisconnect()
{
    statusbar_info(QStringLiteral("连接已断开"));
}

void MapEditWindow::onServerConnectting()
{
    statusbar_info(QStringLiteral("尝试连接服务器..."));
}

void MapEditWindow::onSendFail()
{
    statusbar_err(QStringLiteral("发送请求失败"));
}

void MapEditWindow::onWaitResponseTimeOut()
{
    statusbar_err(QStringLiteral("等待响应超时"));
}
void MapEditWindow::onTip(QString s)
{
    statusbar_info(s);
}
void MapEditWindow::onErr(int errcode,QString info)
{
    statusbar_err(getErrorString(errcode)+"  "+info);
}

void MapEditWindow::onNewRequest()
{
    statusbar_err("");
    statusbar_info("");
}
void MapEditWindow::slot_load_map_success()
{
    msgCenter.mapLoad();
}
void MapEditWindow::slot_set_map_success()
{
    this->oneMap = g_onemap.clone();
    //TODO:重新载入//还是要重启
}

void MapEditWindow::createStatusBar()
{
    QStatusBar *statusbar = new QStatusBar(this);
    QLabel *usernamelabel = new QLabel(QStringLiteral("当前用户:")+current_user_info.username);
    QString role_name = "";
    switch (current_user_info.role) {
    case USER_ROLE_VISITOR:
        role_name =QStringLiteral( "未登录");
        break;
    case USER_ROLE_OPERATOR:
        role_name =QStringLiteral( "普通用户");
        break;
    case USER_ROLE_ADMIN:
        role_name =QStringLiteral( "管理员");
        break;
    case USER_ROLE_SUPER_ADMIN:
        role_name =QStringLiteral( "超级管理员");
        break;
    case USER_ROLE_DEVELOP:
        role_name =QStringLiteral( "开发人员");
        break;
    default:
        break;
    }
    QLabel *userrolelabel = new QLabel(QStringLiteral("当前角色:")+role_name);
    info_label = new QLabel(QStringLiteral("信息:"));
    error_label = new QLabel(QStringLiteral("错误:"));
    pos_label = new  QLabel(QStringLiteral("坐标:"));
    usernamelabel->setMinimumWidth(200);
    userrolelabel->setMinimumWidth(200);
    info_label->setMinimumWidth(200);
    error_label->setMinimumWidth(400);
    pos_label->setMinimumWidth(100);

    statusbar->addWidget(usernamelabel);
    statusbar->addWidget(userrolelabel);
    statusbar->addWidget(info_label);
    statusbar->addWidget(error_label);

    statusbar->addWidget(pos_label);

    setStatusBar(statusbar);
}

void MapEditWindow::createActions()
{

    dockMapTree = new DockMapTree(oneMap);
    dockProperty = new DockProperty(oneMap);
    dockView = new DockView(oneMap);
    blockView = new DockBlock(oneMap);
    groupView = new DockGroup(oneMap);
    blockView->hide();
    groupView->hide();

    addDockWidget(Qt::LeftDockWidgetArea,dockMapTree);
    addDockWidget(Qt::LeftDockWidgetArea,dockProperty);
    addDockWidget(Qt::RightDockWidgetArea,dockView);
    tabifyDockWidget(dockMapTree,blockView);
    tabifyDockWidget(blockView,groupView);


    QMenu *mapMenu = menuBar()->addMenu(tr("地图"));
    QMenu *viewsMenu = menuBar()->addMenu(tr("视图"));
    QMenu *toolsMenu = menuBar()->addMenu(tr("工具"));
    QToolBar *mapsToolBar = addToolBar(tr("Maps"));
    QToolBar *viewsToolBar = addToolBar(tr("Views"));
    QToolBar *selectToolBar = addToolBar(tr("Selects"));
    QToolBar *toolsToolBar = addToolBar(tr("Tools"));


    viewsMenu->addAction(dockMapTree->toggleViewAction());
//    viewsToolBar->addAction(dockMapTree->toggleViewAction());

    viewsMenu->addAction(dockProperty->toggleViewAction());
//    viewsToolBar->addAction(dockProperty->toggleViewAction());

    viewsMenu->addAction(dockView->toggleViewAction());
//    viewsToolBar->addAction(dockView->toggleViewAction());

    viewsMenu->addAction(blockView->toggleViewAction());
//    viewsToolBar->addAction(blockView->toggleViewAction());

    viewsMenu->addAction(groupView->toggleViewAction());
//    viewsToolBar->addAction(groupView->toggleViewAction());

    QMenu *helpMenu = menuBar()->addMenu(tr("帮助"));
    QAction *aboutAct = helpMenu->addAction(tr("&About"));
    aboutAct->setStatusTip(tr("Show the application's About box"));

    QAction *aboutQtAct = helpMenu->addAction(tr("About &HY"));
    aboutQtAct->setStatusTip(tr("Show the HY's About box"));

    toolSave = new QAction(this);
    toolSave->setText("保存地图");
    toolSave->setCheckable(false);
    toolSave->setObjectName("toolSave");

    toolCreateMap = new QAction(this);
    toolCreateMap->setText("新建地图");
    toolCreateMap->setCheckable(false);
    toolCreateMap->setObjectName("toolCreateMap");

    toolLoad = new QAction(this);
    toolLoad->setText("加载地图...");
    toolLoad->setObjectName("toolLoad");
    toolLoad->setCheckable(false);


    toolEditStation = new QAction(this);
    toolEditStation->setText("修改站点");
    toolEditStation->setCheckable(false);
    toolEditStation->setObjectName("toolEditStation");

    toolEditPath = new QAction(this);
    toolEditPath->setText("修改路径");
    toolEditPath->setCheckable(false);
    toolEditPath->setObjectName("toolEditPath");

    toolMergeMap = new QAction(this);
    toolMergeMap->setText("合并地图");
    toolMergeMap->setCheckable(false);
    toolMergeMap->setObjectName("toolMergeMap");


    mapMenu->addAction(toolSave);
    mapMenu->addAction(toolLoad);
    mapMenu->addAction(toolCreateMap);
    mapMenu->addAction(toolEditStation);
    mapMenu->addAction(toolEditPath);
    mapMenu->addAction(toolMergeMap);

    mapsToolBar->addAction(toolSave);
    mapsToolBar->addAction(toolLoad);



    selectSelect = new QAction(this);
    selectSelect->setText("旋转");
    selectSelect->setObjectName("selectSelect");
//    QIcon iconSelectSelect;
//    iconSelectSelect.addFile(":/images/toolbar/edit-delete-2.png",QSize(),QIcon::Normal,QIcon::Off);
//    selectSelect->setIcon(iconSelectSelect);
    selectSelect->setCheckable(true);
    selectToolBar->addAction(selectSelect);
    toolsMenu->addAction(selectSelect);

    selectHand = new QAction(this);
    selectHand->setText("拖拽");
    selectHand->setObjectName("selectHand");
//    QIcon iconSelectHand;
//    iconSelectHand.addFile(":/images/toolbar/point-report.22.png",QSize(),QIcon::Normal,QIcon::Off);
//    selectHand->setIcon(iconSelectHand);
    selectHand->setCheckable(true);
    selectToolBar->addAction(selectHand);
    toolsMenu->addAction(selectHand);

    selectDisplayAll = new QAction(this);
    selectDisplayAll->setText("显示全部");
    selectDisplayAll->setObjectName("displayAll");
//    QIcon iconSelectHand;
//    iconSelectHand.addFile(":/images/toolbar/point-report.22.png",QSize(),QIcon::Normal,QIcon::Off);
//    selectHand->setIcon(iconSelectHand);
    selectDisplayAll->setCheckable(false);
    selectToolBar->addAction(selectDisplayAll);
    toolsMenu->addAction(selectDisplayAll);

    selectDisplayItemRatioIncrease = new QAction(this);
    selectDisplayItemRatioIncrease->setText("放大");
    selectDisplayItemRatioIncrease->setObjectName("displayItemRatioIncrease");
//    QIcon iconSelectHand;
//    iconSelectHand.addFile(":/images/toolbar/point-report.22.png",QSize(),QIcon::Normal,QIcon::Off);
//    selectHand->setIcon(iconSelectHand);
    selectDisplayItemRatioIncrease->setCheckable(false);
    selectToolBar->addAction(selectDisplayItemRatioIncrease);
    toolsMenu->addAction(selectDisplayItemRatioIncrease);

    selectDisplayItemRatioDecrease = new QAction(this);
    selectDisplayItemRatioDecrease->setText("缩小");
    selectDisplayItemRatioDecrease->setObjectName("displayItemRatioDecrease");
//    QIcon iconSelectHand;
//    iconSelectHand.addFile(":/images/toolbar/point-report.22.png",QSize(),QIcon::Normal,QIcon::Off);
//    selectHand->setIcon(iconSelectHand);
    selectDisplayItemRatioDecrease->setCheckable(false);
    selectToolBar->addAction(selectDisplayItemRatioDecrease);
    toolsMenu->addAction(selectDisplayItemRatioDecrease);

    toolRestoreBeforeMap = new QAction(this);
    toolRestoreBeforeMap->setText("撤消");
    toolRestoreBeforeMap->setObjectName("toolRestoreBeforeMap");
//    QIcon iconSelectHand;
//    iconSelectHand.addFile(":/images/toolbar/point-report.22.png",QSize(),QIcon::Normal,QIcon::Off);
//    selectHand->setIcon(iconSelectHand);
    toolRestoreBeforeMap->setCheckable(false);
    selectToolBar->addAction(toolRestoreBeforeMap);
    toolsMenu->addAction(toolRestoreBeforeMap);

    toolErase = new QAction(this);
    toolErase->setText("擦除");
    toolErase->setObjectName("toolErase");
    QIcon iconErase;
    iconErase.addFile(":/images/toolbar/edit-delete-2.png",QSize(),QIcon::Normal,QIcon::Off);
    toolErase->setIcon(iconErase);
    toolErase->setCheckable(true);
    toolsToolBar->addAction(toolErase);
    toolsMenu->addAction(toolErase);

    toolStationDraw = new QAction(this);
    toolStationDraw->setText("绘图点");
    toolStationDraw->setObjectName("toolStationDraw");
    QIcon iconStationDraw;
    iconStationDraw.addFile(":/images/toolbar/point-report.22.png",QSize(),QIcon::Normal,QIcon::Off);
    toolStationDraw->setIcon(iconStationDraw);
    toolStationDraw->setCheckable(true);
    toolsToolBar->addAction(toolStationDraw);
    toolsMenu->addAction(toolStationDraw);

    toolStationReport = new QAction(this);
    toolStationReport->setText("报告点");
    toolStationReport->setObjectName("toolStationReport");
    QIcon iconStationReport;
    iconStationReport.addFile(":/images/toolbar/point-halt.22.png",QSize(),QIcon::Normal,QIcon::Off);
    toolStationReport->setIcon(iconStationReport);
    toolStationReport->setCheckable(true);
    toolsToolBar->addAction(toolStationReport);
    toolsMenu->addAction(toolStationReport);

    toolStationHalt = new QAction(this);
    toolStationHalt->setText("休息点");
    toolStationHalt->setObjectName("toolStationHalt");
    QIcon iconStationHalt;
    iconStationHalt.addFile(":/images/toolbar/point-park.22.png",QSize(),QIcon::Normal,QIcon::Off);
    toolStationHalt->setIcon(iconStationHalt);
    toolStationHalt->setCheckable(true);
    toolsToolBar->addAction(toolStationHalt);
    toolsMenu->addAction(toolStationHalt);

    toolStationCharge = new QAction(this);
    toolStationCharge->setText("充电站");
    toolStationCharge->setObjectName("toolStationCharge");
    QIcon iconStationCharge;
    iconStationCharge.addFile(":/images/point/ChargingStation.20x20.png",QSize(),QIcon::Normal,QIcon::Off);
    toolStationCharge->setIcon(iconStationCharge);
    toolStationCharge->setCheckable(true);
    toolsToolBar->addAction(toolStationCharge);
    toolsMenu->addAction(toolStationCharge);

    toolStationLoad = new QAction(this);
    toolStationLoad->setText("载货点");
    toolStationLoad->setObjectName("toolStationLoad");
    QIcon iconStationLoad;
    iconStationLoad.addFile(":/images/menu/arrow-up-3.png",QSize(),QIcon::Normal,QIcon::Off);
    toolStationLoad->setIcon(iconStationLoad);
    toolStationLoad->setCheckable(true);
    toolsToolBar->addAction(toolStationLoad);
    toolsMenu->addAction(toolStationLoad);

    toolStationUnload = new QAction(this);
    toolStationUnload->setText("卸货点");
    toolStationUnload->setObjectName("toolStationUnload");
    QIcon iconStationUnload;
    iconStationUnload.addFile(":/images/menu/arrow-down-3.png",QSize(),QIcon::Normal,QIcon::Off);
    toolStationUnload->setIcon(iconStationUnload);
    toolStationUnload->setCheckable(true);
    toolsToolBar->addAction(toolStationUnload);
    toolsMenu->addAction(toolStationUnload);

    toolStationLoadUnload = new QAction(this);
    toolStationLoadUnload->setText("载货卸货点");
    toolStationLoadUnload->setObjectName("toolStationLoadUnload");
    QIcon iconStationLoadUnload;
    iconStationLoadUnload.addFile(":/images/point/TransferStation.20x20.png",QSize(),QIcon::Normal,QIcon::Off);
    toolStationLoadUnload->setIcon(iconStationLoadUnload);
    toolStationLoadUnload->setCheckable(true);
    toolsToolBar->addAction(toolStationLoadUnload);
    toolsMenu->addAction(toolStationLoadUnload);

    toolStationOrigin = new QAction(this);
    toolStationOrigin->setText("原始点");
    toolStationOrigin->setObjectName("toolStationOrigin");
    QIcon iconStationOrigin;
    iconStationOrigin.addFile(":/images/menu/help-contents.png",QSize(),QIcon::Normal,QIcon::Off);
    toolStationOrigin->setIcon(iconStationOrigin);
    toolStationOrigin->setCheckable(true);
//    toolsToolBar->addAction(toolStationOrigin);
    toolsMenu->addAction(toolStationOrigin);

    toolLine = new QAction(this);
    toolLine->setText("直线");
    toolLine->setObjectName("toolLine");
    QIcon iconLine;
    iconLine.addFile(":/images/toolbar/path-direct.22.png",QSize(),QIcon::Normal,QIcon::Off);
    toolLine->setIcon(iconLine);
    toolLine->setCheckable(true);
    toolsToolBar->addAction(toolLine);
    toolsMenu->addAction(toolLine);

//全部统一用三次曲线
//    toolQb = new QAction(this);
//    toolQb->setText("2次曲线");
//    toolQb->setObjectName("toolQb");
//    QIcon iconQb;
//    iconQb.addFile(":/images/toolbar/path-bezier.22.png",QSize(),QIcon::Normal,QIcon::Off);
//    toolQb->setIcon(iconQb);
//    toolQb->setCheckable(true);
//    toolsToolBar->addAction(toolQb);
//    toolsMenu->addAction(toolQb);

    toolCb = new QAction(this);
    toolCb->setText("3次曲线");
    toolCb->setObjectName("toolCb");
    QIcon iconCb;
    iconCb.addFile(":/images/toolbar/path-bezier.22.png",QSize(),QIcon::Normal,QIcon::Off);
    toolCb->setIcon(iconCb);
    toolCb->setCheckable(true);
    toolsToolBar->addAction(toolCb);
    toolsMenu->addAction(toolCb);

    addBkgd = new QAction(this);
    addBkgd->setText("设置背景图片");
    addBkgd->setObjectName("addBkgd");
    //            QIcon iconAddBkg;
    //            iconAddBkg.addFile(":/images/toolbar/path-bezier.22.png",QSize(),QIcon::Normal,QIcon::Off);
    //            addBkgd->setIcon(iconCb);
    addBkgd->setCheckable(true);
    toolsToolBar->addAction(addBkgd);
    toolsMenu->addAction(addBkgd);

    recordStationPosition = new QAction(this);
    recordStationPosition->setText("载入点位置");
    recordStationPosition->setObjectName("recordStationPosition");
    //            QIcon iconAddBkg;
    //            iconAddBkg.addFile(":/images/toolbar/path-bezier.22.png",QSize(),QIcon::Normal,QIcon::Off);
    //            addBkgd->setIcon(iconCb);
    recordStationPosition->setCheckable(false);
    toolsToolBar->addAction(recordStationPosition);
    toolsMenu->addAction(recordStationPosition);



}

void MapEditWindow::about()
{
    QMessageBox::about(this, tr("About Application"),
                       tr("调度系统客户端."));
}

void MapEditWindow::aboutHY()
{
    QMessageBox::about(this, tr("About "),
                       tr("欢迎使用本系统"));
}

void MapEditWindow::statusbar_info(QString msg)
{
    info_label->setText(QStringLiteral("信息:")+msg);
}

void MapEditWindow::statusbar_err(QString msg)
{
    error_label->setText(QStringLiteral("错误:")+msg);
}

void MapEditWindow::statusbar_pos(QString msg)
{
    pos_label->setText(QStringLiteral("坐标:")+msg);
}

void MapEditWindow::slot_currentMousePos(QPointF pos)
{
    QString tmpPose="(";
    tmpPose+=QString::number(pos.x()*g_mapRatio,'g',4);
    tmpPose+=", "+QString::number(-pos.y()*g_mapRatio,'g',4);//119119
    statusbar_pos(tmpPose);
}

void MapEditWindow::slot_cancelTool()
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolStationOrigin->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);

    selectSelect->setChecked(true);
    selectHand->setChecked(false);
    emit sig_setTool(Scene::T_NONE);
}

void MapEditWindow::on_toolErase_triggered(bool b)
{
    //toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolStationOrigin->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_ERASER);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}

void MapEditWindow::on_toolStationDraw_triggered(bool b)
{
    toolErase->setChecked(false);
    //toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolStationOrigin->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_STATION_DRAW);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}

void MapEditWindow::on_toolStationReport_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    //toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolStationOrigin->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_STATION_REPORT);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}

void MapEditWindow::on_toolStationHalt_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    //toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolStationOrigin->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_STATION_HALT);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}
void MapEditWindow::on_toolStationCharge_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    //toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolStationOrigin->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_STATION_CHARGE);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}
void MapEditWindow::on_toolStationLoad_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    //toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolStationOrigin->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_STATION_LOAD);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}
void MapEditWindow::on_toolStationUnload_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    //toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolStationOrigin->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_STATION_UNLOAD);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}

void MapEditWindow::on_toolStationLoadUnload_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    //toolStationLoadUnload->setChecked(false);
    toolStationOrigin->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_STATION_LOAD_UNLOAD);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}

void MapEditWindow::on_toolStationOrigin_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    //toolStationOrigin->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_STATION_ORIGIN);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}

void MapEditWindow::on_toolLine_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    //toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_LINE);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}
void MapEditWindow::on_toolQb_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolLine->setChecked(false);
    //toolQb->setChecked(false);
    toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_QB);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}
void MapEditWindow::on_toolCb_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    //toolCb->setChecked(false);

    if(b){
        emit sig_setTool(Scene::T_CB);
    }else{
        emit sig_setTool(Scene::T_NONE);
    }
}

void MapEditWindow::on_selectSelect_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);
    //selectSelect->setChecked(false);
    selectHand->setChecked(false);
    emit sig_setTool(Scene::T_NONE);
    emit sig_setSelectSelect();
}

void MapEditWindow::on_selectHand_triggered(bool b)
{
    toolErase->setChecked(false);
    toolStationDraw->setChecked(false);
    toolStationReport->setChecked(false);
    toolStationHalt->setChecked(false);
    toolStationCharge->setChecked(false);
    toolStationLoad->setChecked(false);
    toolStationUnload->setChecked(false);
    toolStationLoadUnload->setChecked(false);
    toolLine->setChecked(false);
//    toolQb->setChecked(false);
    toolCb->setChecked(false);
    selectSelect->setChecked(false);
    //selectHand->setChecked(false);
    emit sig_setTool(Scene::T_NONE);
    if(b)
        emit sig_setSelectHand();
    else
        emit sig_setSelectSelect();
}

void MapEditWindow::on_displayAll_triggered(bool b)
{
    g_itemDisplayRatio=1;
    emit sig_displayAll();
}

void MapEditWindow::on_displayItemRatioIncrease_triggered(bool b)
{
    g_itemDisplayRatio+=0.2;
    qDebug()<<"displayItemRatioIncrease g_itemDisplayRatio"<<g_itemDisplayRatio;


//    paintingActive();
//    emit paintEvent();
//    repaint();
    emit sig_repaint();

}

void MapEditWindow::on_displayItemRatioDecrease_triggered(bool b)
{
    g_itemDisplayRatio-=0.2;
    if(g_itemDisplayRatio<0)
    {
        g_itemDisplayRatio=0.1;
    }


    qDebug()<<"displayItemRatioDecrease g_itemDisplayRatio"<<g_itemDisplayRatio;
//    paintingActive();
//    repaint();
    emit sig_repaint();
}

void MapEditWindow::on_toolSave_triggered(bool b)
{
    switch(msgCenter.getLoginMode())
    {
    case E_LOGIN_MODE_OFFLINE:
    {
        QString fileName = QFileDialog::getSaveFileName(this,
                tr("保存地图文件"),
                D_MAP_FILE_PATH,
                tr("json (*.mjson)"));

            if (!fileName.isNull())
            {
                //fileName是文件名
                oneMap->setVersion(oneMap->getVersion()+1);
                oneMap->setDisplayRatio(g_itemDisplayRatio);
                mapfileParser->saveMapToFile(oneMap,fileName+".mjson");
                QString tmpNote="版本:";
                tmpNote+=QString::number(oneMap->getVersion());
                QMessageBox::information(this,QStringLiteral("地图保存到本地成功"),tmpNote);
            }
            else
            {
                //点的是取消
            }

        break;
    }
    case E_LOGIN_MODE_MONITOR:
    {
        //判断地图是否为空
        std::list<MapFloor *>tmpFlor= oneMap->getFloors();
        if(0==tmpFlor.size())
        {
            QMessageBox::information(this,QStringLiteral("提示"),QStringLiteral("地图为空,禁止保存"));
            break;
        }

        oneMap->setVersion(oneMap->getVersion()+1);
        oneMap->setDisplayRatio(g_itemDisplayRatio);
        std::string mapInfoOut;
        mapfileParser->transMapToString(oneMap,mapInfoOut);
        communicateNormal->writeFleetMap("",mapInfoOut);
        QString tmpNote="版本:";
        tmpNote+=QString::number(oneMap->getVersion());
        QMessageBox::information(this,QStringLiteral("地图保存到远程成功"),tmpNote);
        break;
    }
    case E_LOGIN_MODE_DISPATCH:
    {
        msgCenter.mapSave(oneMap);
        break;
    }
    }

}

void MapEditWindow::on_toolLoad_triggered(bool b)
{
    switch(msgCenter.getLoginMode())
    {
    case E_LOGIN_MODE_OFFLINE:
    {
        //定义文件对话框类
       QFileDialog *fileDialog = new QFileDialog(this);
       fileDialog->resize(400,500);
       //定义文件对话框标题
       fileDialog->setWindowTitle(tr("选择文件"));
       //设置默认文件路径
       QString configFile=D_MAP_FILE_PATH;

       fileDialog->setDirectory(configFile);
       //设置文件过滤器
       fileDialog->setNameFilter(tr("json(*.mjson)"));
       //设置可以选择多个文件,默认为只能选择一个文件QFileDialog::ExistingFiles
       fileDialog->setFileMode(QFileDialog::ExistingFiles);
       //设置视图模式
       fileDialog->setViewMode(QFileDialog::Detail);
       //打印所有选择的文件的路径
       QStringList fileNames;
       if(fileDialog->exec())
       {
           fileNames = fileDialog->selectedFiles();
       }
        qDebug()<<fileNames;
        if(fileNames.size()>0)
        {

            QString filePath =fileNames[0];
            mapfileParser->loadMapFromFile(true,filePath,oneMap);

            if(oneMap->getDisplayRatio()>0)
            {
                 g_itemDisplayRatio=oneMap->getDisplayRatio();
            }

            updateMapShow_slot();


            QFileInfo file_info(filePath);
            QString tmpNote="本地地图版本:";
            tmpNote+=QString::number(oneMap->getVersion())+" 最后编辑:"
                    +file_info.lastModified().toString("yyyy-MM-dd hh:mm:ss");
            QMessageBox::information(this,QStringLiteral("编辑:地图加载成功"),tmpNote);

        }


        break;
    }
    case E_LOGIN_MODE_MONITOR:
    {
        MapFileParse mapfileParser;
        std::string mapInfoReturn;
        communicateNormal->getFleetMap("",mapInfoReturn);
        if(""==mapInfoReturn)
        {
            QMessageBox::information(this,QStringLiteral("提示"),"地图为空,加载失败");
            oneMap->clear();
            lastoneMap->clear();
            updateMapShow_slot();
        }
        else
        {
            mapfileParser.transStringToMap(true,mapInfoReturn,oneMap);

            if(oneMap->getDisplayRatio()>0)
            {
                 g_itemDisplayRatio=oneMap->getDisplayRatio();
            }
            updateMapShow_slot();


            QString tmpNote="远程地图版本:";
            tmpNote+=QString::number(oneMap->getVersion());
            QMessageBox::information(this,QStringLiteral("编辑:地图加载成功"),tmpNote);
            delete lastoneMap;
            lastoneMap=oneMap->clone();


        }


        break;
    }
    case E_LOGIN_MODE_DISPATCH:
    {
        msgCenter.mapLoad();
        break;
    }
    }

}

void MapEditWindow::on_toolCreateMap_triggered(bool b)
{
    qDebug()<<"createNewMap";
    createNewMap();
}

void MapEditWindow::on_toolEditStation_triggered(bool b)
{
    mapStationEditView->showView_slot();
}

void MapEditWindow::on_toolEditPath_triggered(bool b)
{
    pathEditView->showView_slot();
}

void MapEditWindow::on_toolRestoreBeforeMap_triggered(bool b)
{
    QMessageBox::StandardButton rb = QMessageBox::question(this, QStringLiteral("提示"),
                       QStringLiteral("确认撤消刚才的修改?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
    if(rb == QMessageBox::Yes)
    {
       QMessageBox::information(NULL, "提示", "功能未开发", QMessageBox::Yes );
    }
}

void MapEditWindow::on_toolMergeMap_triggered(bool b)
{
    mapMergeView->showView_slot();
}

void MapEditWindow::keyPressEvent(QKeyEvent *event)
{
    if ((event->modifiers() == Qt::ControlModifier) )
    {
        switch (event->key())
        {
        toolCb->setChecked(false);
        case Qt::Key_S:
            on_toolSave_triggered(true);
            break;
        case Qt::Key_L:
            on_toolLine_triggered(true);
            toolLine->setChecked(true);
            break;
        case Qt::Key_J:
            on_toolCb_triggered(true);
            toolCb->setChecked(true);
            break;
        case Qt::Key_E:
            on_toolErase_triggered(true);
            toolErase->setChecked(true);
            break;
        case Qt::Key_P:
            on_toolStationDraw_triggered(true);
            toolStationDraw->setChecked(true);
            break;
        case Qt::Key_H:
            on_selectSelect_triggered(true);
            break;

        default:
            QMainWindow::keyPressEvent(event);
        }
    }
    else
    {
        QMainWindow::keyPressEvent(event);
    }
}

void MapEditWindow::recordStationPositionOnce()
{
    //根据位置类型获取位置

    switch((static_cast<MapPoint *>(choosedSpirit))->getPoseType())
    {
    case E_POSITION_TYPE_COMMON:
    {
        (static_cast<MapPoint *>(choosedSpirit))->setRealX(globalData->vehicleInWorld.position.x);
        (static_cast<MapPoint *>(choosedSpirit))->setRealY(globalData->vehicleInWorld.position.y);
        (static_cast<MapPoint *>(choosedSpirit))->setRealA(globalData->vehicleInWorld.position.rotate*180.0/M_PI);
        if(E_POSITION_TYPE_VMARK!=(static_cast<MapPoint *>(choosedSpirit))->getPoseType())
        {
            double tmpValue=globalData->vehicleInWorld.position.x/g_mapRatio;
            (static_cast<MapPoint *>(choosedSpirit))->setX(tmpValue);//12580todo
            tmpValue=globalData->vehicleInWorld.position.y/g_mapRatio;
                        (static_cast<MapPoint *>(choosedSpirit))->setY(tmpValue);//12580todo
        }
        emit sig_propertyChanged(choosedSpirit);

        break;
    }
    case E_POSITION_TYPE_VMARK:
    {
        (static_cast<MapPoint *>(choosedSpirit))->setRealX(globalData->vehicleInVmark.position.x);
        (static_cast<MapPoint *>(choosedSpirit))->setRealY(globalData->vehicleInVmark.position.y);
        (static_cast<MapPoint *>(choosedSpirit))->setRealA(globalData->vehicleInVmark.position.rotate*180.0/M_PI);

        emit sig_propertyChanged(choosedSpirit);


        break;
    }
    case E_POSITION_TYPE_QRCODE:
    {
        (static_cast<MapPoint *>(choosedSpirit))->setRealX(globalData->vehicleInQrcode.position.x);
        (static_cast<MapPoint *>(choosedSpirit))->setRealY(globalData->vehicleInQrcode.position.y);
        (static_cast<MapPoint *>(choosedSpirit))->setRealA(globalData->vehicleInQrcode.position.rotate*180.0/M_PI);
        if(E_POSITION_TYPE_VMARK!=(static_cast<MapPoint *>(choosedSpirit))->getPoseType())
        {
            double tmpValue=globalData->vehicleInQrcode.position.x/g_mapRatio;
            (static_cast<MapPoint *>(choosedSpirit))->setX(tmpValue);//12580todo
            tmpValue=globalData->vehicleInQrcode.position.y/g_mapRatio;
                        (static_cast<MapPoint *>(choosedSpirit))->setY(tmpValue);//12580todo
        }
        emit sig_propertyChanged(choosedSpirit);

        break;
    }
    case E_POSITION_TYPE_REFLECT:
    {
        (static_cast<MapPoint *>(choosedSpirit))->setRealX(globalData->vehicleInCU1.position.x);
        (static_cast<MapPoint *>(choosedSpirit))->setRealY(globalData->vehicleInCU1.position.y);
        (static_cast<MapPoint *>(choosedSpirit))->setRealA(globalData->vehicleInCU1.position.rotate*180.0/M_PI);
        if(E_POSITION_TYPE_VMARK!=(static_cast<MapPoint *>(choosedSpirit))->getPoseType())
        {
            double tmpValue=globalData->vehicleInCU1.position.x/g_mapRatio;
            (static_cast<MapPoint *>(choosedSpirit))->setX(tmpValue);//12580todo
            tmpValue=globalData->vehicleInCU1.position.y/g_mapRatio;
                        (static_cast<MapPoint *>(choosedSpirit))->setY(tmpValue);//12580todo
        }
        emit sig_propertyChanged(choosedSpirit);
        break;
    }
    default:
    {
    qDebug()<<"error,unknow type";
    return ;
    }
    }
}

int MapEditWindow::createNewMap()
{
//    qDebug()<<"function need todo ";
//    QMessageBox::information(NULL, "提示", "功能未开发,请重启程序新建地图", QMessageBox::Yes );
//    return 1;
    MapPropertyInfo infoOut;
    communicateNormal->getMapPropertyInfo("",infoOut);

    this->oneMap->clear();

    dockMapTree->addFloor_ratio(infoOut.mapRatio);

    dockMapTree->refresh();
    dockView->initialScene();
    emit sig_displayAll();

    //添加背景图片
    QString imageFilePath = D_MAP_FILE_PATH;
    imageFilePath+=QString::fromStdString(infoOut.imageName);

    //file name
    QString imageFileName = QString::fromStdString(infoOut.imageName);

    //data
    QByteArray ba;
    QFile *file = new QFile(imageFilePath);
    file->open(QIODevice::ReadOnly);
    ba = file->readAll();
    file->close();

    //img
    QImage img;
    img.load(imageFilePath);

    MapBackground *_bkg = new MapBackground(oneMap->getNextId(),imageFileName.toStdString(),
                                   ba.data(),ba.length(),img.width(),img.height(),
                                            imageFileName.toStdString());
    _bkg->setX(infoOut.xOffset);
    _bkg->setY(infoOut.yOffset);
    oneMap->addSpirit(_bkg);
    emit sig_addBkg(_bkg->getId());

}

void MapEditWindow::on_addBkgd_triggered(bool b)
{
    if(b){
        toolErase->setChecked(false);
        toolStationDraw->setChecked(false);
        toolStationReport->setChecked(false);
        toolStationHalt->setChecked(false);
        toolStationCharge->setChecked(false);
        toolStationLoad->setChecked(false);
        toolStationUnload->setChecked(false);
        toolStationLoadUnload->setChecked(false);
        toolLine->setChecked(false);
//        toolQb->setChecked(false);
        toolCb->setChecked(false);
        selectSelect->setChecked(false);
        selectHand->setChecked(false);
        emit sig_setTool(Scene::T_NONE);

        if(oneMap->getFloors().size()>0){
            QString filePath = QFileDialog::getOpenFileName(this,tr("Open Image"), D_MAP_FILE_PATH, tr("Image Files (*.pgm *.png *.jpg *.bmp)"));
            if(filePath.length()>0){
                //file name
                QString fileName = filePath.right(filePath.length() - filePath.lastIndexOf("/")-1);

                //data
                QByteArray ba;
                QFile *file = new QFile(filePath);
                file->open(QIODevice::ReadOnly);
                ba = file->readAll();
                file->close();

                //img
                QImage img;
                img.load(filePath);

                MapBackground *_bkg = new MapBackground(oneMap->getNextId(),fileName.toStdString(),
                                               ba.data(),ba.length(),img.width(),img.height(),
                                                        fileName.toStdString());
                oneMap->addSpirit(_bkg);
                emit sig_addBkg(_bkg->getId());
            }
        }
        addBkgd->setChecked(false);
    }
}

void MapEditWindow::on_recordStationPosition_triggered(bool b)
{

    qDebug()<<"载入点位置";
    if(NULL==choosedSpirit || MapSpirit::Map_Sprite_Type_Point!=choosedSpirit->getSpiritType())
    {
        QMessageBox::information(NULL, "提示", "请先在左侧地图树中选择站点", QMessageBox::Yes );
        return;
    }

    recordStationPositionOnce();// 第一次视图会监视到点有变换，然后改变实际坐标，导致精度损失。
    recordStationPositionOnce();


    int stationId=(static_cast<MapPoint *>(choosedSpirit))->getId();
     QString tmpInfo=QString::number(stationId)+"号站点位置载入成功";
     QMessageBox::information(NULL, "提示", tmpInfo, QMessageBox::Yes );

}
